<table id="organTable" style="height:100%;" data-options="">
</table>
<% if(organ.levelnum==2||organ.levelnum==0||organ.levelnum==1){ %>
<div id="tb" >
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editUser()">禁用/启用</a>
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="initPass()">重置密码</a>
</div>
<%}else{%>
<div id="tb" >
	<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="initPass()">重置密码</a>
</div>
<% } %>
<script>


	function editUser(){
		 parent.$.messager.confirm('Confirm','确定继续更改账号状态吗？',function(r){
				if (r){
					var childGridId = "${childGridId}";
					var $childGrid = $("#" + childGridId);
					 var row = $childGrid.datagrid('getSelected');
					 if(row == null){
						 $.slideMsg("请选中一条记录！", parent.$);
					 }else{
						 $.post("${cxt!}/organization/jyUser", {'ids':row.ids}, function(result) {
								if(result=='200'){
									$.slideMsg("修改成功！", parent.$);
									$childGrid.datagrid('reload');
								}else{
									$.alert($pjq, result);
									
								}
								
							}, 'json');
					 }
				}else{
					//window.location.reload();
				}
			});
		
	}
		function initPass(){
			 parent.$.messager.confirm('Confirm','确定继续重置密码吗？',function(r){
					if (r){
						var childGridId = "${childGridId}";
						var $childGrid = $("#" + childGridId);
						 var row = $childGrid.datagrid('getSelected');
						 if(row == null){
							 $.slideMsg("请选中一条记录！", parent.$);
						 }else{
							 $.post("${cxt!}/organization/initPass", {'ids':row.ids}, function(result) {
									if(result=='200'){
										$.slideMsg("重置成功，新密码为888888！", parent.$);
									}else{
										$.alert($pjq, result);
										
									}
									
								}, 'json');
						 }
					}else{
						window.location.reload();
					}
				});
			
		}

	function lookInfo(ids){
		loadViewDialog('查看信息', 'organization/lookUserInfo?ids=' + ids);
	}
	//初始化机构列表
	function initOrganTable(curNode){
		var title = curNode.name;
		var param = {
					'_query.parentIds': curNode.id
				};
		$.post("${cxt!}/common/getOrganLevelInfo", {'ids':curNode.levelIds}, function(result) {
			if(result){
				$('#organTable').datagrid({
					cls: "theme-datagrid",
					title: title,
					singleSelect: true,
					rownumbers: true, //显示序号
					pagination: true,
					pageSize: 10,
					url: "organization/organList",
					queryParams: param,
				    method: 'post',
					collapsible: true,
					columns:[[
					  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
					  		{field:'name',title:'机构名称',width:100,align:'center'},
					  		{field:'mangerIds',title:'mangerIds',width:100, align:'center', hidden:true},
					  		/* {field:'mangerName',title:'管理员姓名',width:80, align:'center',
					  			formatter: function(value,row,index){
					  				var ids = row.mangerIds;
									return '<a href="#" style="color: blue;" class="button-edit" onclick="lookInfo(\'' + ids + '\')">' + value + '</a>';
								}
					  		}, */
					  		{field:'mangername',title:'管理员姓名',width:160, align:'center'},
					  		{field:'mobile',title:'管理员手机号',width:160, align:'center'}
					  		/* {field:'mangerids',title:'mangerids',width:100, align:'center', hidden:true},
					  		{field:'mangername',title:result.parentmanger,width:80, align:'center',
					  			formatter: function(value,row,index){
					  				var ids = row.mangerids;
									return '<a href="#" style="color: blue;" class="button-edit" onclick="lookInfo(\'' + ids + '\')">' + value + '</a>';
								}
					  		},
					  		{field:'mangermobile',title:result.parentmanger+'手机号',width:160, align:'center'},
					  		{field:'kytime',title:result.time,width:120, align:'center'} */
					      ]],
					onLoadSuccess:function(){
						$('#organTable').datagrid("selectRow", 0);
						// 获取主表选中行
			        	var gridSelectRow = $("#organTable").datagrid('getSelected');
			        	initOrganUserTable(gridSelectRow.ids, gridSelectRow.name);
					},
					onClickRow:function(rowIndex,rowData){
						initOrganUserTable(rowData.ids, rowData.name);
					}
				});
			}else{
				$('#organTable').datagrid({
					cls: "theme-datagrid",
					title: title,
					rownumbers: false,
					columns:[[]],
					onLoadSuccess:function(){
						initOrganUserTable(curNode.id, curNode.name);
					}
				});
				
			}
			
		}, 'json');
		
	}
	//初始化机构用户列表 row为选中行
	function initOrganUserTable(ids,name){
		var childGridId = "${childGridId}";
		var $childGrid = $("#" + childGridId);
		if (typeof(ids) == "undefined") { 
       		$childGrid.datagrid({ 
       			cls: "theme-datagrid",
       			rownumbers: false,
				title: " ",
				columns:[[]]
       		});
       	}else{
        	$childGrid.datagrid({
				cls: "theme-datagrid",
				title: name,
				toolbar: '#tb',
				singleSelect: true,
				rownumbers: true, //显示序号
				pagination: true,
				pageSize: 10,
				url: "organization/organUserList",
				queryParams: {
					'_query.organizationids': ids
				},
			    method: 'post',
				collapsible: true,
				columns:[[
				  		{field:'ids',title:'ids',width:100,align:'center', hidden:true},
				  		{field:'name',title:'姓名',width:100,align:'center'},
				  		{field:'username',title:'用户名',width:100, align:'center'},
				  		{field:'stationname',title:'岗位',width:80, align:'center'},
				  		{field:'mobile',title:'电话',width:160, align:'center'},
				  		{field:'status',title:'状态',width:100, align:'center',
				  			formatter: function(value,row,index){
				  				var status = row.status;
				  				if(status == 1){
				  					return '正常';
				  				}else{
				  					return '禁用';
				  				}
				  			}
				  		}
				      ]]
			});
       	}
	}
</script>